home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6480 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.5 KB  |  50 lines

  1. Path: dawn.mmm.com!news
  2. From: kjhopps@mmm.com (Kevin J Hopps)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Ctors & member methods ?
  5. Date: 8 Feb 1996 21:06:41 GMT
  6. Organization: 3M - St. Paul, MN  55144-1000 US
  7. Message-ID: <4fdol1$7il@dawn.mmm.com>
  8. References: <3100187d.5776685@ixnews7.ix.netcom.com> <4fcuqb$ms7@tic.sm.dsi.unimi.it>
  9. Reply-To: kjhopps@mmm.com
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. ~ZIO BUDDA~ (moreld@dsi.unimi.it) wrote:
  13. > n4jvp (n4jvp@ix.netcom.com) wrote:
  14. > >     I have a question concerning ctors. Can a ctor call a member
  15. > > method? 
  16.  
  17. [example elided]
  18.  
  19. > I say Yes... By this way U call a function of Class Foo from another Function of class Foo.
  20.  
  21. But be aware that the "virtualness" of member functions is not there until
  22. the object is fully constructed.  Consider:
  23.     class Base
  24.     {
  25.     public:
  26.     Base();
  27.     virtual void f();
  28.     };
  29.     class Derived : public Base
  30.     {
  31.     public:
  32.     Derived();
  33.     virtual void f();
  34.     }
  35.     Base::Base()
  36.     {
  37.     f();    // never calls Derived::f()
  38.     }
  39.  
  40. The call to f() in Base::Base() will call Base::f() even if the object
  41. being constructed will ultimately be a Derived.
  42. --
  43. Kevin J. Hopps                  e-mail: kjhopps@mmm.com
  44. 3M Company                      phone:  (612) 737-4643
  45. 3M Center, Bldg. 235-2D-57      fax:    (612) 737-2700
  46. St. Paul, MN 55144-1000         Opinions are my own.  I don't speak for 3M.
  47.     But 3M speaks for me -- I did not write the following line:
  48.  
  49. Opinions expressed herein are my own and may not represent those of 3M.
  50.